package com.danciyixue.boot.dcyx.model.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;

/**
 * 批量账号有效时长选项
 */
public enum EffectiveDurationOption {

    THREE_MONTHS(3),
    SIX_MONTHS(6),
    NINE_MONTHS(9),
    TWELVE_MONTHS(12);

    @EnumValue
    private final int months;

    EffectiveDurationOption(int months) {
        this.months = months;
    }

    public int getMonths() {
        return months;
    }

    public static EffectiveDurationOption fromMonths(int months) {
        for (EffectiveDurationOption value : values()) {
            if (value.months == months) {
                return value;
            }
        }
        throw new IllegalArgumentException("Unsupported months: " + months);
    }

    @JsonCreator
    public static EffectiveDurationOption fromValue(int months) {
        return fromMonths(months);
    }

    @JsonValue
    public int toValue() {
        return months;
    }
}
